/**
 * ChangeManagerAspect.aj
 *
 * Created on Mar 8, 2007 at 11:42:31 PM.
 */
package org.yaorm.aspectj;

import org.yaorm.impl.ChangeManager;

/**
 * Advises the pointcuts of interest for the {@link AspectjChangeManager}.
 * 
 * Such pointcuts are:
 * - a value is assigned to a field annotated with @org.yaorm.field.Persistent, who are members of classes annotated 
 *   with @org.yaorm.type.Persistent 
 * - ... 
 *  
 * For a definition of Property please see  the JavaBeans specification.
 * 
 * OPTIMIZATION NOTES:
 * - we should advice only the changes that are made within a transaction ... or provide the 
 *   extension point to allow for it.
 *   
 * @author <a href="mailto:alexei.guevara@objectivedesigns.ca">Alexei Guevara</a>
 * @version $Revision: 1.7 $ updated on $Date: 2006/02/06 21:33:15 $ by $Author: aguevara $
 */
public privileged aspect ChangeManagerAspect {
    
    //Method theSetter, Object theOldValue, Object theNewValue
    pointcut propertyChanged( Object theInstance, Object theFieldValue ) :
        set( @org.yaorm.field.Persistent * * )
     && within( @org.yaorm.type.Persistent * )
     && this( theInstance )
     && args( theFieldValue );
     
    
    Object around( Object theInstance, Object theFieldValue ) : propertyChanged( theInstance, theFieldValue ) {
        ChangeManager.INSTANCE.notifyFieldChange( theInstance, thisJoinPoint.getSignature().getName(), theFieldValue );
        return theFieldValue;
    }
    
}
